<?php
declare(strict_types=1);
namespace App\Controller\Cash\v1;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use App\Middleware\CashMiddleware;
use Service\OrderService\CashOrderService;
use Service\OrderService\CashReturnOrderService;

/**
 * 订单中心
 * @author chenshubo
 * @Controller(prefix="/cash/v1/Order")
 * @Middleware(CashMiddleware::class)
 */
class OrderController extends AbstractController
{
    /**
     * @Inject
     * @var CashOrderService
     */
    protected $cashOrderService;
    
    /**
     * @Inject
     * @var CashReturnOrderService
     */
    protected $cashReturnOrderService;
    
    /**
     * 提交订单接口
     * @RequestMapping(path="placeorder", methods="post")
     */
    public function placeOrder(RequestInterface $request)
    {
        return $this->cashOrderService->placeOrder(
            $request->getAttribute('cid'),
            $request->getAttribute('mn_sid'),
            $request->getAttribute('manager_id'),
            $request->getAttribute('casher_id'),
            'pos',
            $request->getParsedBody()
            );
    }

    /**
     * 订单查询
     * @RequestMapping(path="orderlist", methods="post")
     */
    public function orderList(RequestInterface $request)
    {
        return $this->cashOrderService->orderList($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }

    /**
     * 退货订单查询
     * @RequestMapping(path="returnorderlist", methods="post")
     */
    public function returnOrderList(RequestInterface $request)
    {
        return $this->cashOrderService->returnOrderList($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }

    /**
     * 退货
     * @RequestMapping(path="returnorder", methods="post")
     */
    public function returnOrder(RequestInterface $request)
    {
        return $this->cashReturnOrderService->returnOrder(
                $request->getAttribute('cid'),
                $request->getAttribute('mn_sid'),
                $request->getAttribute('manager_id'),
                $request->getAttribute('casher_id'),
                $request->getParsedBody()
                );
    }
    
    /**
     * 自提单查询
     * @RequestMapping(path="selforderlist", methods="post")
     */
    public function selfOrderList(RequestInterface $request)
    {
        return $this->cashOrderService->selfOrderList($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }
    
    /**
     * 自提单核销
     * @RequestMapping(path="selforderreview", methods="post")
     */
    public function selfOrderReview(RequestInterface $request)
    {
        return $this->cashOrderService->selfOrderReview($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }

    /**
     * 订单核销接口
     * @RequestMapping(path="bondedSelfOrderReview", methods="post")
     */
    public function bondedSelfOrderReview(RequestInterface $request)
    {
        return $this->cashOrderService->bondedSelfOrderReview($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$request->getParsedBody());
    }
    
    /**
     * 订单重新申报(物流单)
     * @RequestMapping(path="reportagain", methods="post")
     */
    public function reportAgain(RequestInterface $request)
    {
        return $this->cashOrderService->reportAgain($request->getParsedBody());
    }


    /**
     * 计算优惠券及积分
     * @RequestMapping(path="coupon", methods="post")
     */
    public function coupon(RequestInterface $request)
    {
        $body=$request->getParsedBody();
        $body['is_order']=0;
        return CashOrderService::instance()->getCouponPoints($request->getAttribute('cid'),$request->getAttribute('mn_sid'),$body);
    }

    /**
     * 组合装改价获取新的税费
     * @RequestMapping(path="getCombineGoodsTaxFee", methods="post")
     */
    public function getCombineGoodsTaxFee(RequestInterface $request){
        $body = $request->getParsedBody();
        $body['is_order']=0;
        return CashOrderService::instance()->getCombineGoodsTaxFee($request->getAttribute('cid'),$body);
    }

    /**
     * 拆单详情
     * @RequestMapping(path="combinationOrder",methods="post")
     */
    public function combinationOrder(RequestInterface $request){
        $body = $request->getParsedBody();
        return CashOrderService::instance()->combinationOrder(
            $request->getAttribute('cid'),
            $request->getAttribute('mn_sid'),
            $request->getAttribute('manager_id'),
            $request->getAttribute('casher_id'),
            $body
        );
    }

}